package org.demo.web.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.demo.facade.config.FacadeConfiguration;
import org.demo.web.interceptor.SecurityInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"org.demo.web.controller", "org.demo.web.interceptor"})
@Import({
    FacadeConfiguration.class,
})
public class WebConfiguration extends WebMvcConfigurerAdapter {

    /* ---- Constants ---- */
    private final Log log = LogFactory.getLog(getClass());

    /* --- Instance Variables ---- */

    @Autowired
    private SecurityInterceptor securityInterceptor;


    /* ---- Constructors ---- */

    public WebConfiguration() {
        super();
        log.info("WebConfiguration - demo-web");
    }

    /* ---- Configuration Beans ---- */

	@Override
	public void addInterceptors(InterceptorRegistry  registry) {
	    registry.addInterceptor(securityInterceptor).addPathPatterns("/private/**");
    }

    /* ---- Getters and Setters ---- */

	public SecurityInterceptor getSecurityInterceptor() {
		return securityInterceptor;
	}

	public void setSecurityInterceptor(SecurityInterceptor securityInterceptor) {
		this.securityInterceptor = securityInterceptor;
	}

}
